import axios from "axios";
// 整体持久化
const init = {
  movieList: []
};
const state = JSON.parse(localStorage.getItem("vuex_movie")) || init;
const mutations = {
  // 修改电影列表
  setmovieList(state, payload) {
    state.movieList = payload.movieList;
    localStorage.setItem("vuex_movie", JSON.stringify(state));
  }
};
const actions = {
  // 请求电影的列表
  async getmovieList({ commit }) {
    const result = await axios.get("https://pcw-api.iqiyi.com/search/recommend/list?channel_id=1&data_type=1&mode=11&page_id=2&ret_num=48&session=b9fd987164f6aa47fad266f57dffaa6a");
    commit("setmovieList", { movieList: result.data.data.list });
  }
};
const getters = {
  // 电影名字长度在3-6位的
  getmovieList3_6(state) {
    return state.movieList.filter(item => {
      if (item.name.length > 2 && item.name.length < 7) {
        return item;
      }
    });
  }
};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
};